//
//  CommodityView.m
//  1243
//
//  Created by apple on 16/7/1.
//  Copyright © 2016年 1243. All rights reserved.
//

#import "CommodityView.h"
#import "OneKindCell.h"
#import "TwoKindCell.h"

@interface CommodityView ()<UITableViewDelegate,UITableViewDataSource>
@property (nonatomic, strong)UITableView *mainTV;
@end


@implementation CommodityView

-(instancetype)initWithFrame:(CGRect)frame {
    if (self = [super initWithFrame:frame]) {
        self.mainTV = [[UITableView alloc]initWithFrame:frame];
        
        self.mainTV.delegate = self;
        self.mainTV.dataSource = self;
        
        self.mainTV.showsVerticalScrollIndicator = NO;
        [self.mainTV registerClass:[OneKindCell class] forCellReuseIdentifier:@"ONECELL"];
        [self.mainTV registerClass:[TwoKindCell class] forCellReuseIdentifier:@"TWOCELL"];
        [self addSubview:self.mainTV];
    }
    return self;
}

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return 10;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    if (indexPath.row == 0) {
        if (self.aititudeNum == 0) {
            return 315;
        }else if (self.aititudeNum == 1){
            return 450;
        }else if (self.aititudeNum == 2) {
            return 450;
        }
    }
    return 50;
    
}

- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section {
    return 50;
}

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
    return 0.01;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    if (indexPath.row == 0) {
        OneKindCell *cell = [self.mainTV dequeueReusableCellWithIdentifier:@"ONECELL" forIndexPath:indexPath];
        [cell.mainPic setImage:[UIImage imageNamed:@"watch"]];
        cell.titleLB.text = @"经典皮质复古表";
        cell.peopleCountLB.text = @"总需XXX人次";
        cell.qiLB.text = @"第XXX期";
        cell.restCountLB.text = @"已满";

        
        
        
        if (self.aititudeNum == 0) {
            [cell passAititude:0];
        }else if (self.aititudeNum == 1) {
            [cell passAititude:1];
        }else if (self.aititudeNum == 2) {
            [cell passAititude:2];
        }
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
        return cell;
        
    }
    
    TwoKindCell *cell = [self.mainTV dequeueReusableCellWithIdentifier:@"TWOCELL" forIndexPath:indexPath];
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    if (indexPath.row == 1) {
        [cell setUI:0];
    }else if (indexPath.row == 2){
        [cell setUI:1];
    }else  {
        [cell setUI:2];
    }
    
    return cell;
    
    
}


@end
